package com.msmall.community.admin.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.msmall.base.service.impl.BaseManagerImpl;
import com.msmall.community.admin.dao.AdminUserDao;
import com.msmall.community.admin.model.AdminUser;
import com.msmall.community.admin.service.AdminSecurityManager;

public class AdminSecurityManagerImpl extends BaseManagerImpl implements AdminSecurityManager{
	
	private static final Log log = LogFactory.getLog(AdminSecurityManagerImpl.class);
	
	private AdminUserDao adminUserDao;
	
	public void setAdminUserDao(AdminUserDao adminUserDao) {
		this.adminUserDao = adminUserDao;
	}

	public boolean authenticate(String username, String password){
		try {
			AdminUser admin = getByUsername(username);
			if(admin != null){
				if(admin.getPassword().equals(password)){
					return true;
				}
			}
		} catch (Exception e) {
			log.error(e);
		}
		return false;
	}
	
	public AdminUser getByUsername(String username){
		try{
			return adminUserDao.loadUserByUsername(username);
		}catch(Exception e){
			log.error(e);
		}
		return null;
	}
}
